<?php
/**
 * @author Amissah Gideon<kuulmek@yahoo.com>
 * @access public
 * @version 1.0
 */
$tenor_opts = array();
for ($x = 1; $x <= 500; $x++) {
    $tenor_opts[$x] = $x;
}

$months_opts = array();
for ($x = 1; $x <= 500; $x++) {
    $months_opts[$x] = $x;
}
$decimal_places_opts = array();
for ($x = 1; $x <= 20; $x++) {
    $decimal_places_opts[$x] = $x;
}
$purchase_type_opt = array("Interest Payment"=>"Interest Payment","Non Interest Payment"=>"Non Interest Payment","Outright Payment"=>"Outright Payment");
?>
<script type="text/javascript">
    var global_item_data = <?php echo json_encode($global_item_data); ?>;
    var global_customers = <?php echo json_encode($customerOpt); ?>;
</script>

<!-- Main content -->
<section role="main" id="main">

    <!-- Header -->
    <?php
        echo $this->element('page_header');
        echo $this->element('navigations/sales_navbar');
    ?>

    <div class="with-padding">
        <div class="columns">
            <div class="new-row-mobile twelve-columns six-columns-tablet twelve-columns-mobile">

                <h3 class="thin underline">Create A New Sale</h3>
                <p class="wrapped left-icon icon-info-round">
                    <b><?php  echo __('Transaction Currency:');?></b> <?php echo $this->Form->input('gbl_currency', array('div' => false, 'label' => false, 'id' => 'gbl_currency', 'class' => 'select blue-gradient', 'options' => $currency_opts, 'default' => '$')); ?>
                    &nbsp;&nbsp;
                    &nbsp;&nbsp;<?php  echo __('USD Conversion Rate:');?> <input type="text" id="conversion_rate" size="5" class= "input usd_rate_text" value="<?php echo $buying_usd_rate;?>" />
                </p>
            </div>
            <div class="new-row-tablet new-row-mobile six-columns twelve-columns-tablet twelve-columns-mobile">

                <?php echo $this->Form->create('Sale', array('default' => false, 'id' => 'form', 'action' => 'add','inputDefaults' => array('label' => false,'div' => false)));?>
                <fieldset class="fieldset">
                    <legend class="legend">Info</legend>

                    <p class="button-height inline-label">
                        <label class="label">Customer:</label>
                        <?php echo $this->Form->input('customer_id', array('div' => false, 'label' => false, 'id' => 'customer_id', 'class' => 'select expandable-list', 'style'=>'width:250px;', 'options' => $customerOpt)); ?>
                        <?php echo $this->Form->input('currency', array('type' => 'hidden', 'div' => false, 'label' => false, 'id' => 'currency', 'class' => '', 'value' => '$'));?>
                    </p>

                    <p class="button-height inline-label">
                        <label class="label">Total Cost:</label>
                        <?php echo $this->Form->input('cost', array('type' => 'text', 'readonly' => 'readonly', 'div' => false, 'label' => false, 'id' => 'cost', 'class' => 'input', 'value' => '0.00')); ?>
                    </p>
					
					 <p class="button-height inline-label">
                        <label class="label">Purchase Type:</label>
                        <?php echo $this->Form->input('purchase_type', array( 'div' => false, 'label' => false, 'id' => 'purchase_type', 'class' => 'select blue-gradient', 'options' => $purchase_type_opt));  ?>
                    </p>

                    <p class="button-height inline-label">
                        <label class="label">Interest % per Anum:</label>
                        <?php echo $this->Form->input('interest', array('type' => 'text', 'div' => false, 'label' => false, 'id' => 'interest', 'class' => 'input validate[required,custom[number]]', 'value' => '0.00')); ?>
                    </p>

                    <p class="button-height inline-label">
                        <label class="label">Total # of Periods:</label>
                        <?php echo $this->Form->input('duration_in_month', array('div' => false, 'label' => false, 'id' => 'duration_in_month', 'class' => 'select', 'options' => $months_opts)); ?>
                        <?php echo $this->Form->input('tenor', array('type' => 'hidden', 'div' => false, 'label' => false, 'id' => 'tenor', 'default' => 1)); ?>
                    </p>

                    <p class="button-height inline-label">
                        <label class="label">Discount %:</label>
                        <?php echo $this->Form->input('discount', array('type' => 'text', 'div' => false, 'label' => false, 'id' => 'discount', 'class' => 'input validate[required,custom[number]]', 'value' => '0.00')); ?>
                    </p>

                    <p class="button-height inline-label">
                        <label class="label">Purchase Date:</label>
                        <span class="input">
                            <?php echo $this->Form->input('purchased_date', array('type'=>'text','id'=>'purchased_date', 'class' => 'input-unstyled validate[required]',  'value'=>date('Y-m-d'),'readonly' => 'readonly','div' => false, 'label' => false,)); ?>
                            <a href="javascript:void(0)" class="button compact" id="purchased_date_btn">Date</a>
                        </span>
                    </p>

                    <p class="button-height inline-label">
                        <label class="label">Deposit Currency:</label>
                        <?php echo $this->Form->input('deposit_currency', array( 'div' => false, 'label' => false, 'id' => 'deposit_currency', 'class' => 'select', 'options' => $currency_opts, 'default' => '$'));  ?>
                    </p>

                    <p class="button-height inline-label">
                        <label class="label">Deposit :</label>
                        <?php echo $this->Form->input('deposit', array('type' => 'text', 'div' => false, 'label' => false, 'id' => 'deposit', 'class' => 'input validate[required,custom[number]]', 'value' => '0.00')); ?>
                    </p>

                    <p class="button-height inline-label" id="deposit_conversion_rate_txt">
                        <label class="label">Deposit In USD:</label>
                        <span><b>0.00</b></span>
                    </p>

                    <p class="button-height inline-label">
                        <label class="label">Payment Type:</label>
                        <?php echo $this->Form->input('payment_type', array( 'div' => false, 'label' => false, 'id' => 'payment_type', 'class' => 'select', 'options' => $pay_type_opt));  ?>
                    </p>
					
					<p class="button-height inline-label">
                        <label class="label">Cheque No.:</label>
                        <?php echo $this->Form->input('cheque_no', array( 'div' => false, 'label' => false, 'id' => 'cheque_no', 'class' => 'input'));  ?>
                    </p>

                    <p class="button-height inline-label">
                        <label class="label">Officer In Charge :</label>
                        <?php echo $this->Form->input('officer_incharge', array('type' => 'text', 'div' => false, 'label' => false, 'id' => 'officer_incharge', 'class' => 'input validate[required]', 'value' => '')); ?>
                    </p>
					
					<p class="button-height inline-label">
                        <label class="label">Interest Ratio Decimal Places:</label>
                        <?php echo $this->Form->input('interest_rate_decimal_places', array('div' => false, 'label' => false, 'id' => 'interest_rate_decimal_places', 'class' => 'select', 'default'=>'4' ,'options' => $decimal_places_opts)); ?>
                    </p>

                    <p class="button-height inline-label" id="interest_rate_decimal_place_txt">
                        <label class="label">Interest Rate Per Month:</label>
                        <span><b>.0000</b></span>
                    </p>

                    <p class="button-height inline-label" style="display: none">
                        <label class="label">Tax Per Item % :</label>
                        <?php echo $this->Form->input('tax', array('type' => 'text', 'div' => false, 'label' => false, 'id' => 'tax', 'class' => 'input validate[required,custom[number]]', 'value' => '0.00')); ?>
                    </p>

                    <p class="button-height inline-label">
                        <button type="submit" class="button blue-gradient" id="recalc-btn">
                            Re Calculate
                        </button>
                    </p>

                    <hr />

                    <p class="button-height inline-label" id="items_purchased_txt">
                        <label class="label">Total Items Purchased:</label>
                        <span><b>0.00</b></span>
                    </p>

                    <p class="button-height inline-label" id="priciple_txt">
                        <label class="label">Total Principle:</label>
                        <span><b>0.00</b></span>
                    </p>

                    <p class="button-height inline-label" id="discount_txt">
                        <label class="label">Discount Amount:</label>
                        <span><b>0.00</b></span>
                    </p>

                    <p class="button-height inline-label" id="costafter_discount_txt">
                        <label class="label">Cost After Discount:</label>
                        <span><b>0.00</b></span>
                    </p>

                    <p class="button-height inline-label" id="deposit_txt">
                        <label class="label">Deposit Amount:</label>
                        <span><b>0.00</b></span>
                    </p>

                    <p class="button-height inline-label" id="monthly_inst_txt">
                        <label class="label">Monthly Installment:</label>
                        <span><b>0.00</b></span>
                    </p>

                    <p class="button-height inline-label" id="total_interest_txt">
                        <label class="label">Total Interest:</label>
                        <span><b>0.00</b></span>
                    </p>

                    <p class="button-height inline-label" id="balance_txt">
                        <label class="label">Balance:</label>
                        <span><b>0.00</b></span>
                    </p>

                    <p class="button-height inline-label" id="insurance_txt">
                        <label class="label">Insurance Total:</label>
                        <span><b>0.00</b></span>
                    </p>

                    <p class="button-height inline-label" id="opening_balance_txt">
                        <label class="label">Opening Balance:</label>
                        <span><b>0.00</b></span>
                        <?php echo $this->Form->input('on_credit', array('type' => 'hidden', 'div' => false, 'label' => false, 'id' => 'on_credit', 'value' => 'n')); ?>
                    </p>

                    <hr />

                    <p class="button-height inline-label">
                        <label class="label">Comments:</label>
                        <?php echo $this->Form->input('comments', array('id'=>'comments', 'class' => 'input full-width', 'div' => false, 'label' => false,)); ?>
                    </p>

                    <p class="button-height inline-label">
                        <label for="print_invoice" class="label">Print Receipt</label>
                        <input type="checkbox" name="print_invoice" class="switch medium" id="print_invoice" value="1" checked="checked" data-text-on="Yes" data-text-off="No"/>
                        <?php /*echo $this->Form->input('print_receipt', array('type'=>'checkbox','div' => false, 'label' => false, 'id'=>'print_receipt' ,'class' => '', 'checked'=>'checked'));*/?>
                    </p>

                    <p class="button-height inline-label">
                        <label for="save-btn" class="label">&nbsp;</label>
                        <button type="submit" class="button" id="save-btn">
                            <span class="button-icon green-gradient"><span class="icon-download"></span></span>
                            Save
                        </button>

                        <button type="button" class="button" id="cancel-btn">
                            <span class="button-icon anthracite-gradient"><span class="icon-cross-round"></span></span>
                            Cancel
                        </button>
                    </p>

                </fieldset>

                <?php echo $this->Form->end();?>

            </div>

            <!-- Credit Transaction Details -->

            <div class="new-row-tablet new-row-mobile six-columns twelve-columns-tablet twelve-columns-mobile" id="shopping-cart-window">

                <div class="boxed credit-detail-window">
                    <div class="new-row-tablet new-row-mobile twelve-columns twelve-columns-tablet twelve-columns-mobile" style="margin:0;">
                        <p class="button-height inline-label">
                            <button type="submit" class="button blue-gradient" id="load-cart-from-proforma-btn">
                                <!--<span class="button-icon green-gradient"><span class="icon-plus-round"></span></span>-->
                                Load from Proforma
                            </button>
                        </p>
                        <p class="button-height">
                            <label for="save-btn" class="label" id="proforma_number-text"></label>
                        </p>
                    </div>
                </div>

                <hr />

                <div class="boxed credit-detail-window">
                    <p style="font-size: 14px; font-weight:bold; text-align: center ">Shopping Cart</p>

                    <div class="new-row-tablet new-row-mobile twelve-columns twelve-columns-tablet twelve-columns-mobile">
                        <?php echo $this->Form->input('select_items', array('id' => 'select_items', 'multiple' => 'multiple', 'size' => '8', 'class' => 'select multiple white-gradient allow-empty easy-multiple-selection check-list full-width', 'options' => $ItemOpt)); ?>
                        <!--<select class="select multiple white-gradient allow-empty easy-multiple-selection check-list full-width" multiple>
                            <option value="1">First value</option>
                            <option value="2">Second value</option>
                            <option value="3">Multiple</option>
                            <option value="4">Last value</option>
                        </select>-->
                    </div>

                    <div class="new-row-tablet new-row-mobile twelve-columns twelve-columns-tablet twelve-columns-mobile" style="margin:20px 0;">
                        <p class="button-height inline-label">

                            <button type="submit" class="button" id="add-to-cart-btn">
                                <span class="button-icon green-gradient"><span class="icon-plus-round"></span></span>
                                Add To Cart
                            </button>

                            <button type="button" class="button" id="remove-from-cart-btn">
                                <span class="button-icon anthracite-gradient"><span class="icon-trash"></span></span>
                                Remove From Cart
                            </button>
                        </p>
                    </div>

                    <div class="new-row-tablet new-row-mobile twelve-columns twelve-columns-tablet twelve-columns-mobile">

                        <div class="block margin-bottom " >

                            <h3 class="block-title" style="font-size: 14px; line-height: 0px;">
                                Cart Items
                                <span class="count" id="cart-count" style="right: 80%; margin: -8px -25px 0 0;">0</span>
                                <!--<a href="javascript: void(0);" id="update_insurance_btn" class="compact button blue-gradient icon-undo" style="left: 120px;">Update Insurance Cost</a>-->
                            </h3>

                            <div class="with-padding scrollable" style="max-height: 370px; padding: 0px 10px !important;">
                                <div id="cart" class="cart" >
                                    <ul class="list spaced">

                                    </ul>
                                </div>

                            </div>

                        </div>

                    </div>
                </div>

            </div>
        </div>
    </div>

</section>
<!-- End main content -->

<!-- Side tabs shortcuts -->
<?php echo $this->element('side_tabs_shortcuts'); ?>
<!-- Sidebar/drop-down menu -->
<?php echo $this->element('right_side_infos'); ?>



<!-- Users URL -->
<input type="hidden" id="table-url" value="<?php echo $this->Html->url(array('controller' => 'Sales', 'action' => 'get')); ?>"/>
<input type="hidden" id="add-edit-url" value="<?php echo $this->Html->url(array('controller' => 'Sales', 'action' => 'add')); ?>"/>
<input type="hidden" id="load-user-url" value="<?php echo $this->Html->url(array('controller' => 'Sales', 'action' => 'load')); ?>"/>
<input type="hidden" id="delete-url" value="<?php echo $this->Html->url(array('controller' => 'Sales', 'action' => 'delete_')); ?>"/>
<input type="hidden" id="print-sale-receipt-url" value="<?php echo $this->Html->url(array('controller' => 'Sales', 'action' => 'print_sale_receipt')); ?>" />
<input type="hidden" id="search-proforma-url" value="<?php echo $this->Html->url(array('controller' => 'Sales', 'action' => 'search_proforma')); ?>" />


<?php
echo $this->Html->script('setup.js');

/** Template functions **/
echo $this->Html->script('developr.input.js');
echo $this->Html->script('developr.message.js');
echo $this->Html->script('developr.modal.js');
echo $this->Html->script('developr.navigable.js');
echo $this->Html->script('developr.notify.js');
echo $this->Html->script('developr.scroll.js');
echo $this->Html->script('developr.progress-slider.js');
echo $this->Html->script('developr.tooltip.js');
echo $this->Html->script('developr.confirm.js');
echo $this->Html->script('developr.agenda.js');
echo $this->Html->script('developr.tabs.js');

echo $this->Html->script('libs/tinycon.min.js');
echo $this->Html->script('jquery.thfloat-0.3.min.js');
echo $this->Html->script('search.js');
echo $this->Html->script('custom-scripts/sales.js');
?>
